package com.cloudm.technician.ui.modules.common.splash

import android.os.Bundle
import android.view.View
import com.cloudm.technician.extensions.openActivity
import com.cloudm.technician.ui.base.BaseFragment
import com.cloudm.technician.ui.modules.common.guide.GuideActivity
import com.cloudm.technician.ui.modules.common.home.HomeActivity
import com.cloudm.technician.ui.modules.common.login.LoginActivity

/**
 * 作者: wesley
 * 时间: 2017/12/13
 * 描述: ui
 */
class SplashFragment : BaseFragment<SplashPresenter>(), SplashContract.View {

    companion object {
        fun newInstance() = SplashFragment()
    }

    override fun initInject() {
        DaggerSplashComponent.builder().appComponent(appComponent).splashPresenterModule(
                SplashPresenterModule(this)).build().inject(this)
    }

    override fun handleBundle(bundle: Bundle) {

    }

    override fun initVariables() {

    }

    override fun initViews(view: View) {
        presenter?.openActivity()
    }

    override fun initListener() {

    }

    override fun openLoginActivity() {
        mContext.openActivity(LoginActivity::class.java, false)
        destroySelf()
    }

    override fun openGuideActivity() {
        mContext.openActivity(GuideActivity::class.java, false)
        destroySelf()
    }

    override fun openHomeActivity() {
        mContext.openActivity(HomeActivity::class.java, false)
        destroySelf()
    }

    override fun destroySelf() {
        val activity = mContext as? SplashActivity ?: return
        activity.finish()
    }

}